package com.haixiaoke.saas.manage.lock.controller;

import com.haixiaoke.saas.common.core.domain.AjaxResult;
import com.haixiaoke.saas.common.core.page.TableDataInfo;
import com.haixiaoke.saas.lock.domain.DeviceLock;
import com.haixiaoke.saas.lock.service.IDeviceLockService;
import com.haixiaoke.saas.system.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 设备锁Controller
 *
 * @author panda
 * @date 2025-04-02
 */
@RestController
@RequestMapping("/manage/lock/deviceLock")
public class ManageDeviceLockController extends BaseController {
    @Autowired
    private IDeviceLockService deviceLockService;

    /**
     * 分页查询设备锁列表
     *
     * @param deviceLock
     * @return
     */
    @GetMapping("/page")
    public TableDataInfo page(DeviceLock deviceLock) {
        startPage();
        List<DeviceLock> list = deviceLockService.selectDeviceLockList(deviceLock);
        return getDataTable(list);
    }

    /**
     * 获取设备锁详细信息
     */
    @GetMapping(value = "/{lockId}")
    public AjaxResult getInfo(@PathVariable("lockId") Long lockId) {
        return success(deviceLockService.selectDeviceLockById(lockId));
    }

    /**
     * 新增设备锁
     */
    @PostMapping
    public AjaxResult add(@RequestBody DeviceLock deviceLock) {
        deviceLock.setCreateBy(getUsername());
        return deviceLockService.manageInsertDeviceLock(deviceLock);
    }

    /**
     * 删除设备信息
     */
    @DeleteMapping("/{lockId}")
    public AjaxResult remove(@PathVariable Long lockId) {
        return deviceLockService.deleteDeviceLockByLockId(lockId, null);
    }
}
